<!-- 角色列表 -->
<template>
  <div class="rolelist">
    <el-col :span="24">
      <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 20px;">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>角色列表</el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>
    <el-card class="box-card">
      <div class="text item" style="line-height: 0;text-align: left;">
        <el-button type="primary">新增角色</el-button>
        <el-table :data="tableData" style="width: 100%" border>
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-col>
                <el-row>
                  <el-col :span="4">
                    <el-form label-position="left" inline class="demo-table-expand"
                      v-for="(firstLevel, firstIndex) in props.row.children">
                      <el-form-item>
                        <el-tag>{{ firstLevel.authName }}</el-tag>
                      </el-form-item>
                    </el-form>
                  </el-col>
                  <el-col :span="4">
                    <el-form label-position="left" inline class="demo-table-expand"
                      v-for="(firstLevel, firstIndex) in props.row.children">
                      <el-form-item v-for="item in firstLevel.children">
                        <el-tag>{{ item.authName }}</el-tag>
                      </el-form-item>
                    </el-form>
                  </el-col>
                  <el-col :span="16">
                    <el-form label-position="left" inline class="demo-table-expand"
                      v-for="(firstLevel, firstIndex) in props.row.children">
                      <div v-for="(item, index) in firstLevel.children">
                        <el-form-item v-for="val in item.children">
                          <el-tag>{{ val.authName }}</el-tag>
                        </el-form-item>
                      </div>
                    </el-form>
                  </el-col>
                </el-row>
              </el-col>
            </template>
          </el-table-column>
          <el-table-column label="">
            <!-- 箭头 -->
            <template slot-scope="scope">
              <el-icon>
                <arrow-right />
              </el-icon>
            </template>
          </el-table-column>
          <el-table-column label="" prop="id">
          </el-table-column>
          <el-table-column label="角色名称" prop="roleName">
          </el-table-column>
          <el-table-column label="描述" prop="roleDesc">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary">编辑</el-button>
              <el-button type="danger">删除</el-button>
              <el-button type="info">设置</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  data() {
    return {
      baseURL: 'http://43.138.15.137:7000/api/private/v1',
      token: localStorage.getItem('token'),
      tableData: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async getRoleList() {
      const res = await axios.get(this.baseURL + '/roles', {
        headers: {
          'Authorization': this.token
        }
      }).then(res => {
        let data = res.data.data
        this.tableData = data
        console.log(this.tableData);
        console.log(this.tableData[0].children);
      })
    }
  }
}
</script>
